package com.library.web.controller.api;

import com.library.common.core.domain.AjaxResult;
import com.library.domain.AppActivity;
import com.library.domain.AppBanner;
import com.library.service.IAppActivityService;
import com.library.service.IAppBannerService;
import com.library.web.controller.vo.BannerModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author julyWhj
 * @Description $
 * @Date 2022/3/27 9:11 上午
 **/
@RestController
@RequestMapping("/api/banner")
public class BannerApiController {
    @Autowired
    private IAppBannerService bannerService;
    @Autowired
    private IAppActivityService activityService;

    @GetMapping
    public AjaxResult getBanners() {
        AppBanner appBannerReq = new AppBanner();
        List<AppBanner> appBanners = bannerService.selectAppBannerList(appBannerReq);
        List<BannerModel> bannerModels = new ArrayList<>();
        appBanners.forEach(appBanner -> {
            String activityNo = appBanner.getActivityNo();
            AppActivity appActivity = activityService.selectAppActivityByActivityNo(activityNo);
            BannerModel bannerModel = BannerModel.toModel(appBanner);
            bannerModel.setAppActivity(appActivity);
            bannerModels.add(bannerModel);
        });
        return AjaxResult.success(bannerModels);
    }
}
